#pragma once
#ifndef myWindowlet_h__
#define myWindowlet_h__

#include "./myControl.h"

#include "../inc/skyInput.h"
#include "../inc/skySocket.h"
#include "../inc/skyFile.h"

#include "../inc/skyFont.h"
#include "../inc/skyPict.h"
#include "../inc/skyCanvas.h"
#include "../inc/skyPainter.h"


namespace Sky
{
//class myEventSender;
//class myMenuBar;
//class myMsgWindow;
//class myMsgBox;
	class myEvent;
	class myMsgMgr;
	class myResMgr;
	using namespace Sky;
	
	class myWinlet : public myControl
	{
		friend class TreeMgr;
		friend class myWinMgr;
		
		DECL_RTTI1(myWinlet,myControl);

	private:
		Bool m_bActived;
		Rect m_DirtyRect;
		myControlManager m_CtlManager;
		myControl*   m_Focused;
		public:
		//called only by myWinManager
		virtual Bool init(myResMgr* resManager,i32 x,i32 y,i32 w,i32 h);
		//called only by myWinManager
		virtual Void unInit();
	public:
		myWinlet();
		myWinlet(i32 id);
		virtual ~myWinlet();

		static Bool   doCommand(u32 command,u32 data);

		MsgStatus handlePostEvent(myMsgMgr* mgr,Msg* msg);
		MsgStatus handleSendEvent(myMsgMgr* mgr,Msg* msg);
		MsgStatus handleUIEvent( myMsgMgr* mgr,Msg* msg );

	protected:
		virtual MsgStatus	onPostEvent(	myMsgMgr* mgr,Msg* msg);
		virtual MsgStatus	onSendEvent(	myMsgMgr* mgr,Msg* msg);
		virtual MsgStatus	onFocusNext(	myMsgMgr* mgr,Msg* msg);
		virtual MsgStatus   onFocusPrev(	myMsgMgr* mgr,Msg* msg);
		virtual MsgStatus	onSizeChange(	myMsgMgr* mgr,Msg* msg);
		virtual MsgStatus	onInput(		myMsgMgr* mgr,Msg* msg);
		/*virtual TResult	onTimer(		myEventManager* mgr,myEvent* event){return vUnHandled;};*/
	public:
		//
		Void setActive(Bool active){m_bActived = active;}
		//
		Bool isActive(){return m_bActived;}

		//images in rect is invalid,need redraw 
		Bool InvalidateArea( Rect* rect );
		//control need redraw
		Bool InvalidateControl( myControl* ctrl);
		//
		Void Draw(Sky::Painter* painter);
		Void Draw(Sky::Painter* painter,myControl* ctrl);
		
		
		
		myControlManager* getControlManager(){return &m_CtlManager;}
	};

	typedef RefPtr<myWinlet> myWinletPtr;

	class myWinMsg : public myCtrlMsg
	{
		DECL_RTTI1(myWinMsg,myCtrlMsg);
		DECL_MESSAGE(myWinlet,myWinMsg,myCtrlMsg);
	};

	typedef RefPtr<myWinMsg> myWinletMsgPtr;
}
#endif // myWindowlet_h__
